/************************************************************
* @file gkt_core_irq.h
************************************************************/

#ifndef GKT_CORE_IRQ_H
#define GKT_CORE_IRQ_H

#include "gkt_types.h"

#ifdef __cplusplus
extern "C" {
#endif

/* IRQ handle */
typedef void (*gkt_irq_handler)(void);

/* IRQ Priority */
#define GKT_IRQ_PRIORITY_L1(PRIO_NAME)	\
	GKT_IRQ_PRIORITY_##PRIO_NAME
#define GKT_IRQ_PRIORITY(PRIO_NAME)	\
	GKT_IRQ_PRIORITY_L1(PRIO_NAME)

/* IRQ Flags */
#define GKT_IRQ_F_ENABLE	(1U << 0)
#define GKT_IRQ_F_UNMASK	(1U << 1)
#define GKT_IRQ_F_CLEAR	(1U << 2)
#define GKT_IRQ_F_SHARE	(1U << 3)

typedef struct _gkt_irq_attr {
	uint32_t	flags;
	uint32_t	priority;
	gkt_irq_handler	handler;
	/* ... */
} gkt_irq_attr_s;

/*
 * @brief core interrupt init
 */
void gkt_irq_init(void);

/*
 * @brief setup & release IRQ
 */
int gkt_irq_setup(uint32_t no, gkt_irq_attr_s *attr);
void gkt_irq_release(uint32_t no);

/*
 * @brief check whether is in the irq context
 */
int gkt_irq_context(void);

/*
 * @brief get irq active or not
 * @return 1-active, 0-inactive
 */
//int gkt_irq_is_active(uint32_t no);

/*
 * @brief get current interrupt number
 */
uint32_t gkt_irq_get_current(void);

/*
 * @brief get & set the prioeirt of interrupt-no
 */
uint32_t gkt_irq_get_priority(uint32_t no);
void gkt_irq_set_priority(uint32_t no, uint32_t priority);

/*
 * disable & enable the global interrupt
 */
void gkt_irq_global_enable(void);
void gkt_irq_global_disable(void);

/*
 * @brief enable & disable interrupt-no
 */
void gkt_irq_enable(uint32_t no);
void gkt_irq_disable(uint32_t no);

/*
 * @brief set/clear interrupt pending
 */
void gkt_irq_set_pending(uint32_t no);
void gkt_irq_clear_pending(uint32_t no);

/*
 * default irq handler
 */
void gkt_irq_default_handler(void);


#ifdef __cplusplus
}
#endif

#endif	/* GKT_CORE_IRQ_H */

